package com.company.genealogy.web.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.company.genealogy.web.entity.Member;
import lombok.Data;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class MemberExportVO {
    @ExcelProperty("姓名")
    private String name;
    @ExcelProperty("性别")
    private String gender;
    @ExcelProperty("世代")
    private Integer generation;
    @ExcelProperty("家族")
    private String clanName;
    @ExcelProperty("分支")
    private String branchName;
    @ExcelProperty("出生日期")
    private String birthDate;
    @ExcelProperty("去世日期")
    private String deathDate;
    @ExcelProperty("父亲")
    private String fatherName;
    @ExcelProperty("母亲")
    private String motherName;
    @ExcelProperty("配偶")
    private String spouseName;
    @ExcelProperty("联系方式")
    private String contact;
    @ExcelProperty("籍贯省")
    private String nativeProvinceName;
    @ExcelProperty("籍贯市")
    private String nativeCityName;
    @ExcelProperty("籍贯区县")
    private String nativeCountyName;
    @ExcelProperty("籍贯镇")
    private String nativeTownName;
    @ExcelProperty("现住地址")
    private String currentAddress;
    @ExcelProperty("个人事迹")
    private String story;
    @ExcelProperty("状态")
    private String status;

    public static List<MemberExportVO> fromEntityList(List<Member> list) {
        return list.stream().map(MemberExportVO::fromEntity).collect(Collectors.toList());
    }

    public static MemberExportVO fromEntity(Member m) {
        MemberExportVO vo = new MemberExportVO();
        vo.setName(m.getName());
        vo.setGender("M".equals(m.getGender()) ? "男" : ("F".equals(m.getGender()) ? "女" : ""));
        vo.setGeneration(m.getGeneration());
        vo.setClanName(m.getClanName());
        vo.setBranchName(m.getBranchName());
        vo.setBirthDate(m.getBirthDate() != null ? m.getBirthDate().toString() : "");
        vo.setDeathDate(m.getDeathDate() != null ? m.getDeathDate().toString() : "");
        vo.setFatherName(m.getFatherName());
        vo.setMotherName(m.getMotherName());
        vo.setSpouseName(m.getSpouseName());
        vo.setContact(m.getContact());
        vo.setNativeProvinceName(m.getNativeProvinceName());
        vo.setNativeCityName(m.getNativeCityName());
        vo.setNativeCountyName(m.getNativeCountyName());
        vo.setNativeTownName(m.getNativeTownName());
        vo.setCurrentAddress(m.getCurrentAddress());
        vo.setStory(m.getStory());
        vo.setStatus(m.getStatus() != null && m.getStatus() == 1 ? "在世" : "已故");
        return vo;
    }
} 